<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath }"/>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>栏目列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="${path}/back-end-jsp/css/font.css">
        <link rel="stylesheet" href="${path}/back-end-jsp/css/index.css">
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script type="text/javascript" src="${path}/js/jquery-3.6.4.js"></script>
        <script src="${path}/back-end-jsp/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="${path}/back-end-jsp/js/index.js"></script>

        <style>
            th,tr{
                text-align: center;
                vertical-align: middle!important;
            }
             #current{
                 display: inline-block;
                 background: #09b4c5;
                 color: #fff;
                 padding: 5px;
                 min-width: 15px;
                 border: 1px solid #09b4c5;
             }
        </style>
    </head>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">电影管理</a>
                <a><cite>电影列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" action="${path}/MovieServlet?prom=showAll" method="post">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="电影名" name="movie_cn_name">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" type="submit"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>

                            </form>
                            <div class="layui-input-inline layui-show-xs-block">
                                <button class="layui-btn" onclick="xadmin.open('添加电影信息','${path}/back-end-jsp/movie-add.jsp',1200,600)"><i class="layui-icon"></i>添加</button>
                            </div>

                            <hr>
                        </div>
                        <div class="layui-card-body">
                            <table class="layui-table layui-form">
                                <thead>
                                    <tr style="text-align: center">
                                        <th>剧照</th>
                                        <th>电影名</th>
                                        <th>类型</th>
                                        <th>地区</th>
                                        <th>导演</th>
                                        <th>演员</th>
                                        <th>片长</th>
                                        <th>上映时间</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody class="x-cate">
                                <c:choose>
                                    <c:when test="${empty movieList}">
                                        <script>window.location="${path}/servlet/backEndJsp/selPageMovie";</script>
                                    </c:when>
                                        <c:otherwise>
                                        <c:forEach var="ml" items="${movieList}">
                                            <tr cate-id='1' fid='0' >
                                                <td class="a1"><%--<img src="${path}/images/moviePicture/${ml.movie_picture}">--%></td>
                                                <td class="a2">${ml.movieCnName}</td>
                                                <td class="a3">${ml.movieFgName}</td>
                                                <td class="a4">${ml.movieDuration}</td>
                                                <td class="a5">${ml.movieAddressId}</td>
                                                <td class="a6">${ml.movieScore}</td>
                                                <td class="a7">${ml.movieBoxOffice}</td>
                                                <td class="a8">${ml.movieCommentCount}</td>
                                                <td ></td>
                                                <td class="a9">
                                                    <c:if test="${ml.movieState==0}">
                                                        下架
                                                    </c:if>
                                                    <c:if test="${ml.movieState==1}">
                                                        待审核
                                                    </c:if>
                                                    <c:if test="${ml.movieState==2}">
                                                        上架
                                                    </c:if>
                                                    <c:if test="${ml.movieState==3}">
                                                        开售
                                                    </c:if>
                                                    <c:if test="${ml.movieState==4}">
                                                        驳回
                                                    </c:if>

                                                </td>
                                              <td class="td-manage">
                                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改电影信息','${path}/back-end-jsp/movie-edit.jsp?id=${ml.movieId}')"><i class="layui-icon">&#xe642;</i>编辑</button>
                                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="delMovie(${ml.movieId})" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                              </td>
                                            </tr>
                                        </c:forEach>

                              </tbody>
                                <tr style="height: 50px;" >
                                    <th colspan="10" align="center">

                                    </th>
                                </tr>
                            </table>
                            </c:otherwise>
                            </c:choose>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
                                    <c:if test="${pages.currPageNo>1}">
                                        <a class="prev" href="${path}/servlet/backEndJsp/selPageMovie?pageIndex=${pages.currPageNo-1}&movieCnName=${movieCnName}">&lt;&lt;</a>
                                    </c:if>
                                    <c:forEach var="i" begin="1" end="${pages.totalPageCount}">
                                        <a <c:if test="${currPageNo==i}"> id="current"</c:if>
                                           <c:if test="${pages.currPageNo!=i}">class="num"</c:if>
                                                <c:if test="${i==1}"> style="background-color: #09b4c5" </c:if>
                                           href="${path}/servlet/backEndJsp/selPageMovie?pageIndex=${i}&movieCnName=${movieCnName}">${i}</a>
                                    </c:forEach>
                                    <c:if test="${pages.currPageNo<pages.totalPageCount}">
                                    <a class="next" href="${path}/servlet/backEndJsp/selPageMovie?pageIndex=${currPageNo+1}&movieCnName=${movieCnName}">&gt;&gt;</a></div>
                                </c:if>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
          layui.use(['form'], function(){
            form = layui.form;
            
          });

          function delMovie(id){
              var str=confirm("确认删除吗？");
              if (str){
                  $.post("${path}/MovieServlet?prom=delMovie","&id="+id,function (result) {
                      if(result>0){
                          location.reload();
                      }else {
                          alert("删除失败");
                      }
                  });
              }
          }

           /*用户-删除*/
          function member_del(obj,id){
              layer.confirm('确认要删除吗？',function(index){
                  //发异步删除数据
                  $(obj).parents("tr").remove();
                  layer.msg('已删除!',{icon:1,time:1000});
              });
          }

          // 分类展开收起的分类的逻辑
          // 
          $(function(){
            $("tbody.x-cate tr[fid!='0']").hide();
            // 栏目多级显示效果
            $('.x-show').click(function () {
                if($(this).attr('status')=='true'){
                    $(this).html('&#xe625;'); 
                    $(this).attr('status','false');
                    cateId = $(this).parents('tr').attr('cate-id');
                    $("tbody tr[fid="+cateId+"]").show();
               }else{
                    cateIds = [];
                    $(this).html('&#xe623;');
                    $(this).attr('status','true');
                    cateId = $(this).parents('tr').attr('cate-id');
                    getCateId(cateId);
                    for (var i in cateIds) {
                        $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                    }
               }
            })
          })

          var cateIds = [];
          function getCateId(cateId) {
              $("tbody tr[fid="+cateId+"]").each(function(index, el) {
                  id = $(el).attr('cate-id');
                  cateIds.push(id);
                  getCateId(id);
              });
          }
              /*function delMovie(id){
                  var str=confirm("确认删除吗？");
                  if (str){
                      $.post("${path}/MovieServlet?prom=delMovie","&id="+id,function (result) {
                          if(result>0){
                              alert("删除成功");
                              $("#"+id).remove(); //移除当前删除的行
                          }else {
                              alert("删除失败");
                          }
                      });
                  }
              }*/
          function updMovie(movieId){
              window.location="${path}/UpdateMovieServlet?prom=selMovie&movie_id="+movieId;
          }
   
        </script>
    </body>
</html>
